package com.yc.shopping.ui;


import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;

public class Test01 {
	Shell shell;
	Display display;
	Text text_user;
	Text text_pwd;
	public static void main(String[] args) {
		
		//创建对象
		Test01 t = new Test01();
		
		t.open();
		

		
	}
	
	//打开窗口
	public void open() {
		createContents();//创建所有组件
		//打开窗口
		shell.open();
				while(!shell.isDisposed()) {//检验窗体是否关闭
					if(!display.readAndDispatch()) {//检验Display 线程状态是否忙
						display.sleep();//Display 类线程休眠
					}
				}
				display.dispose();
	}
	
	public void createContents() {
		//负责通信
		display = new Display();
		//创建窗口
		shell = new Shell(display);
		//设置大小
		shell.setSize(300,300);
		//设置位置
		shell.setLocation(100, 200);
		//设置标题
		shell.setText("第一个窗口");
		//界面上显示文字
		Label label = new Label(shell,SWT.NONE);
		label.setText("用户登录界面");
		label.setBounds(100, 50, 110, 20);
				
		Label label_user = new Label(shell,SWT.NONE);
		label_user.setText("用户名:");
		label_user.setBounds(80,80,60,20);
				
		Label label_pwd = new Label(shell,SWT.NONE);
		label_pwd.setText("密  码:");
		label_pwd.setBounds(80,110,60,20);
				
		text_user = new Text(shell,SWT.NONE);
		text_user.setBounds(150,80,100,20);
				
		text_pwd = new Text(shell,SWT.NONE);
		text_pwd.setBounds(150,110,100,20);
				
		Button btn_login = new Button(shell,SWT.NONE);
		btn_login.setText("登录");
		btn_login.setBounds(110, 160, 60, 20);
		btn_login.addSelectionListener(new SelectionAdapter() {

			@Override
		public void widgetSelected(SelectionEvent e) {
			//从页面取值
			String name = text_user.getText();
			System.out.println(name);
			}
					
			});
				
		
	}
	
}
